package org.example.jdbc;


import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.List;

/**
 * @author ZerlindaLi create at 2021/4/6 17:39
 * @version 1.0.0
 * @description MemberDao
 */
public class MemberDao extends JdbcTemplate {
    public MemberDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<?> queryAll(){
        String sql = "select * from member";
        return super.executeQuery(sql, new RowMapper<Object>() {
            public Member mapRow(ResultSet rs, int rowNum) throws Exception{
                Member member = new Member();
                member.setUsername(rs.getString("username"));
                member.setPassword(rs.getString("password"));
                member.setNickname(rs.getString("nickname"));
                member.setAge(rs.getInt("age"));
                member.setAddr(rs.getString("addr"));
                return member;
            }
        }, null);
    }
}
